package com.leyou.item.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.BrandDTO;
import com.leyou.item.entity.Brand;
import com.leyou.item.entity.CategoryBrand;
import com.leyou.item.entity.MyPage;
import com.leyou.item.service.BrandService;
import com.leyou.item.service.CategoryBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @GetMapping("/page")
    public ResponseEntity<PageDTO> page(MyPage myPage){
        PageDTO pyPage = brandService.findPyPage(myPage);
        return ResponseEntity.ok(pyPage);
    }
    @GetMapping("/list")
    public ResponseEntity<List<BrandDTO>> getBrandByIds(@RequestParam("ids") List<Long> ids){
        List<BrandDTO> brandByIds = brandService.getBrandByIds(ids);
        return ResponseEntity.ok(brandByIds);
    }

    @GetMapping("/of/category")
    public ResponseEntity<List<BrandDTO>> getBrandByCategoryId(@RequestParam("id")Long id){
        List<BrandDTO> brandByIds = brandService.getBrandByCategoryId(id);
        return ResponseEntity.ok(brandByIds);
    }

    @GetMapping("/{id}")
    public ResponseEntity<BrandDTO> getBrandById(@PathVariable("id")Long id){
        BrandDTO brand = brandService.getBrandById(id);
        return ResponseEntity.ok(brand);
    }

    @PostMapping
    public ResponseEntity<Void> createBrand(
            Brand brand,
            @RequestParam("categoryIds") List<Long> categoryIds){
        brandService.createBrand(brand,categoryIds);
        return ResponseEntity.status(201).build();
    }

    @PutMapping
    public ResponseEntity<Void> updateBrand(
            Brand brand,
            @RequestParam("categoryIds") List<Long> categoryIds){
        brandService.updateBrand(brand,categoryIds);
        return ResponseEntity.status(200).build();
    }


}
